/*
 * @lc app=leetcode.cn id=204 lang=cpp
 *
 * [204] 计数质数
 */

// @lc code=start
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
    int countPrimes(long long n)
    {
        if(n <= 2) return 0;
        vector<int> is_prime(n + 1, 1);
        int ans = 0;
        for(long long i = 2; i < n; i++)
        {
            if(is_prime[i])
            {
                ++ans;
                for(long long j = i * i; j < n; j += i)
                {
                    is_prime[j] = 0;
                }
            }
        }
        return ans;
    }
};
// @lc code=end
